﻿@{
    Layout = "~/Views/Samples/Generic/_Index.cshtml";
}

@section existing_js_onfileselectionchanged
{
        function onFileSelectionChanged(data)
        {
            var hasFiles = kw("@SampleHelper.ResolveId("fileSelector1")").get_Files().length > 0 || kw("@SampleHelper.ResolveId("fileSelector2")").get_Files().length > 0;

            document.getElementById("@SampleHelper.ResolveId("uploadButton", (bool)ViewBag.Project.IsAspNetAjax)").className = "button" + (hasFiles ? "" : " disabled");
        }
}

@section existing_slickupload
{
    <h2 style="clear:both;margin-top:.5em;margin-bottom:0">Selector 1</h2>
    <div class="simple su-slickupload">
        @SampleHelper.RenderComponent("FileSelector", new
    {
        Id = "\"fileSelector1\"",
        OnClientFileAdded = "\"onFileSelectionChanged\"",
        OnClientFileRemoved = "\"onFileSelectionChanged\"",
        ShowDropZoneOnDocumentDragOver = "true",
        UploadConnectorId = "\"slickUpload\""
    }, null, new
    {
        Template = (Func<object, HelperResult>)(
            @<text>
                                <a class="button">
                                    <span><b class="icon add"></b> Add files</span>
                                </a>
                                </text>),
        FolderTemplate = (Func<object, HelperResult>)(
            @<text>
                                <a class="button">
                                    <span><b class="icon add-folder"></b> Add folder</span>
                                </a>
                                </text>),
        DropZoneTemplate = (Func<object, HelperResult>)(
            @<text>
                                <div>Drag and drop files here.</div>                
                                </text>)
    })  
        @SampleHelper.RenderComponent("FileList", new
    {
        Id = "\"fileList1\"",
        FileSelectorId = "\"fileSelector1\""
    }, null, new
    {
        ItemTemplate = (Func<object, HelperResult>)(
            @<text>
                                <div class="filedata">
                                    @SampleHelper.RenderComponent("FileListElement", new { Element = "FileListElementType.FileName" })
                                    &ndash;
                                    @SampleHelper.RenderComponent("FileListElement", new { Element = "FileListElementType.FileSize" }, null, "(calculating)")
                                </div>
                                    @SampleHelper.RenderComponent("FileListRemoveCommand", null, null, "[x]")
                                    @SampleHelper.RenderComponent("FileListElement", new { Element = "FileListElementType.ValidationMessage" })
                                </text>)
    })  
        <div style="clear:both"></div>
    </div>  
    <h2 style="clear:both;margin-top:.5em;margin-bottom:0">Selector 2</h2>
    <div class="simple su-slickupload">
        @SampleHelper.RenderComponent("FileSelector", new
    {
        Id = "\"fileSelector2\"",
        OnClientFileAdded = "\"onFileSelectionChanged\"",
        OnClientFileRemoved = "\"onFileSelectionChanged\"",
        ShowDropZoneOnDocumentDragOver = "true",
        UploadConnectorId = "\"slickUpload\""
    }, null, new
    {
        Template = (Func<object, HelperResult>)(
            @<text>
                                <a class="button">
                                    <span><b class="icon add"></b> Add files</span>
                                </a>
                                </text>),
        FolderTemplate = (Func<object, HelperResult>)(
            @<text>
                                <a class="button">
                                    <span><b class="icon add-folder"></b> Add folder</span>
                                </a>
                                </text>),
        DropZoneTemplate = (Func<object, HelperResult>)(
            @<text>
                                <div>Drag and drop files here.</div>                
                                </text>)
    })  
        @SampleHelper.RenderComponent("FileList", new
    {
        Id = "\"fileList2\"",
        FileSelectorId = "\"fileSelector2\""
    }, null, new
    {
        ItemTemplate = (Func<object, HelperResult>)(
            @<text>
                                <div class="filedata">
                                    @SampleHelper.RenderComponent("FileListElement", new { Element = "FileListElementType.FileName" })
                                    &ndash;
                                    @SampleHelper.RenderComponent("FileListElement", new { Element = "FileListElementType.FileSize" }, null, "(calculating)")
                                </div>
                                    @SampleHelper.RenderComponent("FileListRemoveCommand", null, null, "[x]")
                                    @SampleHelper.RenderComponent("FileListElement", new { Element = "FileListElementType.ValidationMessage" })
                                </text>)
    }) 
        <div style="clear:both"></div>
    </div> 

@SampleHelper.RenderComponent("UploadProgressDisplay", new
{
    Id = "\"uploadProgressDisplay\"",
    UploadConnectorId = "\"slickUpload\"",
}, new { Style = "\"clear:both\"" }, new
{
    Template = (Func<object, HelperResult>)(
        @<text>
            <div id="duringUpload">
                <div>
                    Uploading @SampleHelper.RenderComponent("UploadProgressElement", new { Element = "UploadProgressElementType.FileCount" }) file(s),
                    @SampleHelper.RenderComponent("UploadProgressElement", new { Element = "UploadProgressElementType.ContentLengthText" }, null, "(calculating)").
                </div>
                <div>
                    Currently uploading: @SampleHelper.RenderComponent("UploadProgressElement", new { Element = "UploadProgressElementType.CurrentFileName" })
                    file @SampleHelper.RenderComponent("UploadProgressElement", new { Element = "UploadProgressElementType.CurrentFileIndex" })
                    of @SampleHelper.RenderComponent("UploadProgressElement", new { Element = "UploadProgressElementType.FileCount" }).
                </div>
                <div>
                    Speed: @SampleHelper.RenderComponent("UploadProgressElement", new { Element = "UploadProgressElementType.SpeedText" }, null, "(calculating)")
                </div>
                <div>
                    @SampleHelper.RenderComponent("UploadProgressElement", new { Element = "UploadProgressElementType.TimeRemainingText" }, null, "(calculating)")
                </div>
                <div class="progressBarContainer">
                    @SampleHelper.RenderComponent("UploadProgressBar")
                    <div class="progressBarText">
                        @SampleHelper.RenderComponent("UploadProgressElement", new { Element = "UploadProgressElementType.PercentCompleteText" }, null, "(calculating)")
                    </div>
                </div>
            </div>
            @if (PageData["HasPostProcessStep"] as bool? == true)
            {
            <div id="postProcessing" style="display:none">
                <div>
                    Post processing files...
                </div>
                <div class="progressBarContainer">
                    @SampleHelper.RenderComponent("UploadProgressBar")
                    <div class="progressBarText">
                        @SampleHelper.RenderComponent("UploadProgressElement", new { Element = "UploadProgressElementType.PercentCompleteText" }, null, "(calculating)")
                    </div>
                </div>
            </div>                                            
            }
        </text>)
})

@SampleHelper.RenderComponent("UploadConnector", new
{
    Id = "\"slickUpload\"",
    UploadFormId = (ViewBag.Project.ViewEngine != ViewEngine.WebForms ? "\"uploadForm\"" : null),
    OnUploadComplete = (ViewBag.Project.ViewEngine == ViewEngine.WebForms && ViewBag.Project.Language == CodeLanguage.Cs ? "\"slickUpload_UploadComplete\"" : null),
    UploadProfile = "\"" + ViewBag.Sample.Path.Substring(0, 1).ToLower() + ViewBag.Sample.Path.Substring(1) + "\"",
    OnClientUploadSessionStarted = "\"onSessionStarted\"",
    OnClientBeforeSessionEnd = "\"onBeforeSessionEnd\""
})


    @if (ViewBag.Project.ViewEngine != ViewEngine.WebForms)
    {
    @SampleHelper.RenderComponent("KrystalwareScriptRenderer")
    }
}